﻿using Dycox.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dycox.Reporting
{
    public class ReportElementCollection : OwnedCollection<ReportElement, ContainerElement>
    {
        public ReportElementCollection(ContainerElement parent)
            : base(parent)
        {

        }

        protected virtual bool IsChildValid(ReportElement child)
        {
            return true;
        }

        protected override void SetItemOwner(ReportElement item, ContainerElement parent)
        {
            if (IsChildValid(item))
                item.Parent = parent;
            else
                throw new InvalidOperationException("Child element " + item.GetType().FullName + " is not valid for " + parent.GetType().FullName);
        }

        protected override ContainerElement GetItemOwner(ReportElement item)
        {
            return item.Parent;
        }
    }
}
